package com.rsk.api.info;


import javax.ws.rs.QueryParam;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.rsk.aop.ParamCheck;
import com.rsk.api.common.ReturnUtils;
import com.rsk.service.info.RskInformationService;
import com.rsk.utils.result.Result;
import com.rsk.utils.result.ResultBuilder;
import com.rsk.utils.result.ResultCode;
import com.rsk.utils.tools.PageUtils;

@RestController
@RequestMapping(value="/rsk/information")
public class RskInformationApi {
	
	@Reference(interfaceClass = RskInformationService.class, protocol = "dubbo")
	private RskInformationService rskInformationService;
	
	
	//@RequiresPermissions("coursecategory:save")
	@PostMapping(value="/saveInformation" )
	public Result<String> saveInformation(
			@QueryParam("labelId") @ParamCheck(notNull=true) Long labelId,
		   	@QueryParam("informationType") @ParamCheck(notNull=true) Integer informationType,
		   	@QueryParam("informationTitle") @ParamCheck(notNull=true) String informationTitle,
		   	@QueryParam("informationPhoto") @ParamCheck(notNull=true) String informationPhoto,
		   	@QueryParam("informationUser") @ParamCheck(notNull=true) String informationUser,
		   	@QueryParam("information") String information,
		   	@QueryParam("informationUrl") String informationUrl,
		   	@QueryParam("informationSource") @ParamCheck(notNull=true) Integer informationSource,
		   	@RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = rskInformationService.saveInformation(labelId, informationType, informationTitle, informationPhoto, informationUser, 
				information, informationUrl, informationSource, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	//@RequiresPermissions("coursecategory:update")
	@PostMapping(value="/updateInformation" )
	public Result<String> updateInformation(
			@QueryParam("id") @ParamCheck(notNull=true) Long id,
		 	@QueryParam("informationType") @ParamCheck(notNull=true) Integer informationType,
		   	@QueryParam("informationTitle") @ParamCheck(notNull=true) String informationTitle,
		   	@QueryParam("informationPhoto") @ParamCheck(notNull=true) String informationPhoto,
		   	@QueryParam("informationUser")  @ParamCheck(notNull=true) String informationUser,
		   	@QueryParam("information") String information,
		   	@QueryParam("informationUrl") String informationUrl,
		   	@QueryParam("informationSource") @ParamCheck(notNull=true) Integer informationSource,
		   	@QueryParam("informationRead") Long informationRead,
			@RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		//int i = rskCourseService.updateRskCourse(id, categoryId, courseName, courseIntroduction, courseUrl, courseCover, isRecommend, isOriginal, isSee, operatorUser)
		int i = rskInformationService.updateInformation(id, informationType, informationTitle, informationPhoto, 
				informationUser, information, informationUrl, informationSource, informationRead, operatorUser);
				
		return ReturnUtils.returnDataByOne(i);
	}
	
	//@RequiresPermissions("coursecategory:update")
	@PostMapping(value="/updateInformationRead" )
	public Result<String> updateInformationRead(
			@QueryParam("id") @ParamCheck(notNull=true) Long id,
			@RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		//int i = rskCourseService.updateRskCourse(id, categoryId, courseName, courseIntroduction, courseUrl, courseCover, isRecommend, isOriginal, isSee, operatorUser)
		int i = rskInformationService.updateInformationRead(id);
				
		return ReturnUtils.returnDataByOne(i);
	}
	
	//@RequiresPermissions("coursecategory:update")
	@PostMapping(value="/updateInformationStatus" )
	public Result<String> updateInformationStatus(
			@QueryParam("id") @ParamCheck(notNull=true) Long id,
			@QueryParam("informationStatus") @ParamCheck(notNull=true) Integer informationStatus,
			@RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		//int i = rskCourseService.updateRskCourse(id, categoryId, courseName, courseIntroduction, courseUrl, courseCover, isRecommend, isOriginal, isSee, operatorUser)
		int i = rskInformationService.updateInformationStatus(informationStatus, id, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	
	//@RequiresPermissions("coursecategory:del")
	@PostMapping(value="/delInformation" )
	public Result<String> delInformation(@QueryParam("id") @ParamCheck(notNull=true) Long id,
									 @RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = rskInformationService.delInformation(id, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	

	@SuppressWarnings("rawtypes")
	@PostMapping(value="/selectInformationByPage" )
	public Result<PageUtils> selectInformationByPage(
			@QueryParam("nowPage") @ParamCheck(notNull=true) Integer nowPage,
			@QueryParam("pageSize") @ParamCheck(notNull=true) Integer pageSize,
			@QueryParam("labelID") Long labelID,
			@QueryParam("informationTitle") String informationTitle,
			@RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		PageUtils page = rskInformationService.selectInformationByPage(labelID, informationTitle, nowPage, pageSize);
		return ResultBuilder.success(page, ResultCode.SUCCESS);
	}
}
